from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from mall import settings
def generate_save_token(openid):

    serializer = Serializer(settings.SECRET_KEY, expires_in=3600)
    data = {'openid': openid}
    token = serializer.dumps(data)
    return token.decode()


# from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
# # 1. 创建一个序列化器
# # secret_key 秘钥
# # expires in =None 过期时间  单位是秒
#
# s = Serializer(secret_key=settings.SECRET_KEY,expires_in=3600)
#
# # 2.组织数据
# data = {
#     'openid':'123456789'
# }
#
# # 3.序列化器处理数据
# token = s.dumps(data)
#
# # 4.获取数据，对数据进行解密
# s.loads(token)
#
# # 1.如果token 被篡改 是可以检测到的
# # 2.如果token 过期了 会报错

